'use strict';

/**
 * Config for the router
 */
angular.module('app')
  .run(
    [          '$rootScope', '$state', '$stateParams',
      function ($rootScope,   $state,   $stateParams) {
          $rootScope.$state = $state;
          $rootScope.$stateParams = $stateParams;        
      }
    ]
  )
  .config(
    [          '$stateProvider', '$urlRouterProvider', 'JQ_CONFIG', 
      function ($stateProvider,   $urlRouterProvider, JQ_CONFIG) {
          
          $urlRouterProvider
              .otherwise('/app/dashboard');
          $stateProvider
              // others
              .state('lockme', {
                  url: '/lockme',
                  templateUrl: 'tpl/pages/page_lockme.html'
              })
              .state('signin', {
                  url: '/signin',
                  templateUrl: 'tpl/pages/page_signin.html',
                  resolve: {
                      deps: ['uiLoad',
                        function( uiLoad ){
                          return uiLoad.load( ['js/app/controller/signin.js'] );
                      }]
                  }
              })
              .state('signup', {
                  url: '/signup',
                  templateUrl: 'tpl/pages/page_signup.html',
                  resolve: {
                      deps: ['uiLoad',
                        function( uiLoad ){
                          return uiLoad.load( ['js/app/controller/signup.js'] );
                      }]
                  }
              })
              .state('forgotpwd', {
                  url: '/forgotpwd',
                  templateUrl: 'tpl/pages/page_forgotpwd.html'
              })
              .state('404', {
                  url: '/404',
                  templateUrl: 'tpl/pages/page_404.html'
              })
              .state('app', {
                  abstract: true,
                  url: '/app',
                  templateUrl: 'tpl/app.html'
              })
              .state('app.dashboard', {
                  url: '/dashboard',
                  templateUrl: 'tpl/views/dashboard.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              // return uiLoad.load( ['js/app/controller/dashboard.js'] );
                          }]
                  }
              })
              .state('app.blank', {
                url: '/blank',
                templateUrl: 'tpl/views/blank.html'
              })
              .state('app.table', {
                url: '/table',
                templateUrl: 'tpl/views/datatable.html',
                resolve: {
                    deps: ['uiLoad',
                      function( uiLoad ){
                        let arr = JQ_CONFIG.dataTable.concat([
                            'js/app/controller/datatable.js'
                        ]);
                        return uiLoad.load(arr);
                    }]
                }
              })
              .state('app.dict', {
                  url: '/dict',
                  templateUrl: 'tpl/views/sysDict.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              let arr = JQ_CONFIG.dataTable.concat([
                                  'js/app/controller/sysDict.js'
                              ]);
                              return uiLoad.load(arr);
                          }]
                  }
              })
              .state('app.dictData', {
                  url: '/dictData/:id',
                  param: {id: ""},
                  templateUrl: 'tpl/views/sysDictData.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              let arr = JQ_CONFIG.dataTable.concat([
                                  'js/app/controller/sysDictData.js'
                              ]);
                              return uiLoad.load(arr);
                          }]
                  }
              })
              .state('app.datasource', {
                  url: '/datasource',
                  templateUrl: 'tpl/views/datasource.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              let arr = JQ_CONFIG.dataTable.concat([
                                  'js/app/controller/datasource.js'
                              ]);
                              return uiLoad.load(arr);
                          }]
                  }
              })
              .state('app.template', {
                  url: '/template',
                  templateUrl: 'tpl/views/template.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              let arr = JQ_CONFIG.dataTable.concat([
                                  'js/app/controller/template.js'
                              ]);
                              return uiLoad.load(arr);
                          }]
                  }
              })
              .state('app.templateForm', {
                  url: '/template/form/:id',
                  param: {id: ""},
                  templateUrl: 'tpl/views/templateForm.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              let arr = JQ_CONFIG.dataTable.concat([
                                  'js/other/wangEditor/style.css',
                                  'js/other/wangEditor/index.js',
                                  'js/app/controller/templateForm.js'
                              ]);
                              return uiLoad.load(arr);
                          }]
                  }
              })
              .state('app.project', {
                  url: '/project',
                  templateUrl: 'tpl/views/project.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              let arr = JQ_CONFIG.dataTable.concat([
                                  'js/app/controller/project.js'
                              ]);
                              return uiLoad.load(arr);
                          }]
                  }
              })
              .state('app.projectInfo', {
                  url: '/project/:id',
                  param: {id: ""},
                  templateUrl: 'tpl/views/projectInfo.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              let arr = JQ_CONFIG.dataTable.concat([
                                  'js/app/controller/projectInfo.js'
                              ]);
                              return uiLoad.load(arr);
                          }]
                  }
              })
              .state('app.code', {
                  url: '/code/:id',
                  param: {id: ""},
                  templateUrl: 'tpl/views/code.html',
                  resolve: {
                      deps: ['uiLoad',
                          function( uiLoad ){
                              let arr = JQ_CONFIG.dataTable.concat([
                                  'js/app/controller/code.js'
                              ]);
                              return uiLoad.load(arr);
                          }]
                  }
              })
              // pages
              .state('page', {
                  url: '/page',
                  template: '<div ui-view class="fade-in-down"></div>'
              })
              .state('page.profile', {
                  url: '/profile',
                  templateUrl: 'tpl/pages/page_profile.html'
              })
              .state('page.post', {
                  url: '/post',
                  templateUrl: 'tpl/pages/page_post.html'
              })
              .state('page.search', {
                  url: '/search',
                  templateUrl: 'tpl/pages/page_search.html'
              })
              .state('page.invoice', {
                  url: '/invoice',
                  templateUrl: 'tpl/pages/page_invoice.html'
              })
              .state('page.price', {
                  url: '/price',
                  templateUrl: 'tpl/pages/page_price.html'
              })
      }
    ]
  );
